package com.blacktech.dbu.meta.entity;

import com.blacktech.dbu.core.annotation.Searchable;
import com.blacktech.dbu.core.common.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;

/**
 * 数据表信息
 *
 * @author yanyunsong
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Table(name = "dbu_table")
public class DbuTable extends BaseEntity {
    
    /**
     * 关联的数据库模式
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "schema_id")
    @JsonIgnore
    private DbuSchema schema;
    
    /**
     * 数据表名称
     */
    @Searchable(value = "表名", priority = 1)
    @Column(name = "table_name")
    private String tableName;

    /**
     * 数据表注释
     */
    @Searchable(value = "表注释", priority = 2)
    @Column(name = "table_comment")
    private String tableComment;

    /**
     * 表的字段列表
     */
    @OneToMany(mappedBy = "table", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @JsonIgnore
    private List<DbuColumn> columns;

    /**
     * 表的约束列表
     */
    @OneToMany(mappedBy = "table", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @JsonIgnore
    private List<DbuConstraint> constraints;

    /**
     * 表的索引列表
     */
    @OneToMany(mappedBy = "table", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @JsonIgnore
    private List<DbuIndex> indexes;
}